<pre>
<?php

class LifeCycle
{
	// Basic time unit in this system is seconds
	const MIN 	= 60;
	const HOUR 	= 3600;
	const DAY 	= 86400;
	const WEEK 	= 604800;
	
	// Stages
	const EGG 		= 1;
	const CHILD1 	= 2;
	const CHILD2 	= 3;
	const CHILD3 	= 4;
	const ADULT1 	= 5;
	const BYEBYE 	= 6;
	const REBIRTH 	= 7;

	public static $lifeStageMap = array(
		self::EGG => "卵",
		self::CHILD1 => "幼年期Ⅰ",
		self::CHILD2 => "幼年期Ⅱ",
		self::CHILD3 => "幼年期Ⅲ",
		self::ADULT1 => "成人Ⅰ",
		self::BYEBYE => "消滅前",
		self::REBIRTH => "転生",
	);

	public static $stageLengths = array(
		self::EGG => 180,		// 3 min
		self::CHILD1 => 21600,	// 6 hours
		self::CHILD2 => 28000,	// 8 hours
		self::CHILD3 => 43200,	// 12 hours
		self::ADULT1 => 82800,	// 23 hours
		self::BYEBYE => 3600,	// 1 hour
		self::REBIRTH => 0,	// directly to egg
	);

	// Label on creature info: 「ＸＸまで」
	public static $transitionLabels = array(
		self::EGG => "孵化",
		self::CHILD1 => "変更",
		self::CHILD2 => "変更",
		self::CHILD3 => "変更",
		self::ADULT1 => "転生",
		self::BYEBYE => "転生",
		self::REBIRTH => "散乱",
	);
	
	
	public static function testLifeStage( $age )
	{
		echo "Age:" . $age . "\n";
		$resultStage = self::determineLifeStage( $age );
		echo "Final result stage:" . $resultStage . "\n";
		echo "--------\n";
		echo "\n";
	}
	
	public static function determineLifeStage( $age )
	{
		$stage = 0;
		$compareAge = 0;
		
		for( $stage = self::EGG; $stage <= self::REBIRTH; $stage++ )
		{
			$compareAge += LifeCycle::$stageLengths[$stage];
			echo "stage:" . $stage . "\n";
			echo "compareAge:" . $compareAge . "\n";
			
			if( $age <= $compareAge )
			{
				break;
			}
		}
		
		if( $stage > self::REBIRTH )
		{
			$stage = self::REBIRTH;
		}
		return $stage;
	}

}

LifeCycle::testLifeStage( 179 );
LifeCycle::testLifeStage( 180 );
LifeCycle::testLifeStage( 181 );
LifeCycle::testLifeStage( 20000 );
LifeCycle::testLifeStage( 35000 );
LifeCycle::testLifeStage( 60000 );
LifeCycle::testLifeStage( 100000 );
LifeCycle::testLifeStage( 176000 );
LifeCycle::testLifeStage( 180000 );
LifeCycle::testLifeStage( 604800 );

?>
</pre>

